

;================
;=              =
;= PROGRESS BAR =
;=              =
;================
;
; init_progress(HL=sum of all parts) - init draw_progress
; draw_progress() - vizualize of ratio sum/done
; done - public field (write from depacker)


	.MODULE PRGSBAR

done	.WORD 0000
_unit	.WORD 0000


init_progress
	;HL = sum of all parts in bytes

	sra h
	rr l
	sra h
	rr l
	sra h
	rr l
	sra h
	rr l

	ld (_unit), hl		;unit = sum>>4
	ld hl, 0
	ld (done), hl
	ret

draw_progress
	ld a, (timer)
	and 7
	ret z			;occurs every 8th frame

	xor a			;reset result
	ld de, (_unit)		;divisor
	ld hl, (done)		;dividend

	or a
_draw2
	sbc hl, de		;compute units = done / unit
	jr c, _draw1		;by repeated subtracting - not bad algo for small quotients
	inc a
	jr _draw2
_draw1
	;now A = units done

	ld d, %01111110		;bar graphics
	ld e, %00000000
	ld b, %01000010
	add a, 7		;bar offset
	ld (_draw5 + 1), a	

	ld hl, 
_draw4
	ld a, l		;4
	cp 24 		;7	end of bar
	ret z		;5

	ld (hl), e	;7
	inc h		;4
	ld (hl), d	;7
	inc h		;4
_draw5
	ld a, 0		;7 modified by number of units		
	sub l		;4
	jr c, _draw6	;7 draw todo unit

	ld (hl), d 	;7 draw done unit
	jr _draw3	;4
_draw6
	ld (hl), b
_draw3
	inc h		;4
	ld (hl), d	;7
	inc h		;4
	ld (hl), e	;7
	dec h		;4
	dec h		;4
	dec h		;4
	dec h		;4
	inc l		;4
	jr _draw4	;12 
	
	
	        